import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path*',
      component: () => import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'Dashboard',
      meta: {
        title: '首页',
        icon: 'dashboard',
        affix: true
      }
    }]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [{
    path: '/config',
    component: Layout,
    redirect: '/config/list',
    meta: {
      title: '配置管理',
      icon: 'table'
    },
    children: [{
        path: 'list',
        component: () => import('@/views/config/list'),
        name: 'List',
        meta: {
          title: '七牛配置',
          icon: 'table',
          noCache: true
        }
      },
      {
        path: 'smsList',
        component: () => import('@/views/config/smsList'),
        name: 'smsList',
        meta: {
          title: '短信配置',
          icon: 'table',
          noCache: true
        }
      },
      {
        path: 'appList',
        component: () => import('@/views/config/appList'),
        name: 'appList',
        meta: {
          title: '版本配置',
          icon: 'table',
          noCache: true
        }
      },
      {
        path: 'addressList',
        component: () => import('@/views/config/addressList'),
        name: 'addressList',
        meta: {
          title: '地址管理',
          icon: 'table',
          noCache: true
        }
      },
    ]
  },
  // {
  //    path: '/clipboard',
  //    component: Layout,
  //    children: [{
  //      path: 'index',
  //      component: () => import('@/views/clipboard/index'),
  //      name: 'ClipboardDemo',
  //      meta: {
  //        title: 'Clipboard',
  //        icon: 'clipboard'
  //      }
  //    }]
  //  },

  {
    path: '/clipboard',
    component: Layout,
    children: [{
      path: 'index',
      component: () => import('@/views/clipboard/index'),
      name: 'ClipboardDemo',
      meta: {
        title: 'Clipboard',
        icon: 'clipboard'
      }
    }]
  },

  {
    path: '/rule',
    component: Layout,
    redirect: '/rule/list',
    meta: {
      title: '权限管理',
      icon: 'documentation'
    },
    children: [{
        path: 'list',
        component: () => import('@/views/role/list'),
        name: 'RoleList',
        meta: {
          title: '权限列表',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'group',
        component: () => import('@/views/role/group'),
        name: 'RoleGroup',
        meta: {
          title: '权限组',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'group/edit/:id',
        hidden: true,
        component: () => import('@/views/role/edit-group'),
        name: 'GroupEdit',
        meta: {
          title: '编辑权限组',
          icon: 'documentation',
          noCache: true
        }
      },
      {
        path: 'group/add',
        hidden: true,
        component: () => import('@/views/role/add-group'),
        name: 'GroupAdd',
        meta: {
          title: '添加权限组',
          icon: 'documentation',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/list',
    meta: {
      title: '管理员管理',
      icon: 'user'
    },
    children: [{
        path: 'list',
        component: () => import('@/views/admin/list'),
        name: 'AdminList',
        meta: {
          title: '管理员列表',
          icon: 'user',
          noCache: true
        }
      },
      {
        path: 'adminLogList',
        component: () => import('@/views/admin/adminLogList'),
        name: 'adminLogList',
        meta: {
          title: '操作日志',
          icon: 'user',
          noCache: true
        }
      }
    ]
  },


  {
    path: '/members',
    component: Layout,
    redirect: '/members/list',
    meta: {
      title: '会员管理',
      icon: 'peoples'
    },
    children: [{
        path: 'list',
        component: () => import('@/views/members/list'),
        name: 'MemberList',
        meta: {
          title: '会员列表',
          icon: 'peoples',
          noCache: true
        }
      },
      {
        path: 'financingList',
        component: () => import('@/views/members/financingList'),
        name: 'financingList',
        meta: {
          title: '余额变动记录',
          icon: 'peoples',
          noCache: true
        }
      }, {
        path: 'financingProfit',
        component: () => import('@/views/members/financingProfit'),
        name: 'financingProfit',
        meta: {
          title: '收益变动记录',
          icon: 'peoples',
          noCache: true
        }
      },
      {
        path: 'authList',
        component: () => import('@/views/members/authList'),
        name: 'authList',
        meta: {
          title: '实名认证',
          icon: 'peoples',
          noCache: true
        }
      },
      {
        path: 'paymentList',
        component: () => import('@/views/members/paymentList'),
        name: 'paymentList',
        meta: {
          title: '收款方式',
          icon: 'peoples',
          noCache: true
        }
      },
      {
        path: 'memberRoleList',
        component: () => import('@/views/members/memberRoleList'),
        name: 'memberRoleList',
        meta: {
          title: '权限申请',
          icon: 'peoples',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/money',
    component: Layout,
    redirect: '/money/payOrderList',
    meta: {
      title: '资金管理',
      icon: 'money'
    },
    children: [{
        path: 'payOrderList',
        component: () => import('@/views/money/payOrderList'),
        name: 'payOrderList',
        meta: {
          title: '充值记录',
          icon: 'money',
          noCache: true
        }
      },
      {
        path: 'withdrawalList',
        component: () => import('@/views/money/withdrawalList'),
        name: 'withdrawalList',
        meta: {
          title: '提现管理',
          icon: 'money',
          noCache: true
        }
      },
      {
        path: 'statistics',
        component: () => import('@/views/money/statistics'),
        name: 'withdrawalList',
        meta: {
          title: '统计图表',
          icon: 'money',
          noCache: true
        }
      },
    ]
  },
  {
    path: '/course',
    component: Layout,
    redirect: '/course',
    meta: {
      title: '课程管理',
      icon: 'chart'
    },
    children: [{
        path: 'courseList',
        component: () => import('@/views/course/courseList'),
        name: 'courseList',
        meta: {
          title: '课程列表',
          icon: 'chart',
          noCache: true
        }
      },
      {
        path: 'subList',
        component: () => import('@/views/course/subList'),
        name: 'course/subList',
        meta: {
          title: '子课程列表',
          icon: 'chart',
          noCache: true
        }
      },
    ]
  },
  {
    path: '/group',
    component: Layout,
    redirect: '/group',
    meta: {
      title: '小组管理',
      icon: 'tree'
    },
    children: [{
        path: 'groupList',
        component: () => import('@/views/group/groupList'),
        name: 'groupList',
        meta: {
          title: '小组列表',
          icon: 'tree',
          noCache: true
        }
      },
      {
        path: 'themeList',
        component: () => import('@/views/group/themeList'),
        name: 'group/themeList',
        meta: {
          title: '主题列表',
          icon: 'tree',
          noCache: true
        }
      },
      {
        path: 'commentList',
        component: () => import('@/views/group/commentList'),
        name: 'group/commentList',
        meta: {
          title: '评论列表',
          icon: 'tree',
          noCache: true
        }
      },
      {
        path: 'commentSubList',
        component: () => import('@/views/group/commentSubList'),
        name: 'group/commentSubList',
        meta: {
          title: '回复列表',
          icon: 'tree',
          noCache: true
        }
      },
    ]
  },

  {
    path: '/library',
    component: Layout,
    redirect: '/library',
    meta: {
      title: '申学研',
      icon: 'guide'
    },
    children: [{
        path: 'libraryCateList',
        component: () => import('@/views/library/libraryCateList'),
        name: 'libraryCateList',
        meta: {
          title: '题目类型',
          icon: 'guide',
          noCache: true
        }
      },
      {
        path: 'libraryList',
        component: () => import('@/views/library/libraryList'),
        name: 'libraryList',
        meta: {
          title: '试卷管理',
          icon: 'guide',
          noCache: true
        }
      }, {
        path: 'topicList',
        component: () => import('@/views/library/topicList'),
        name: 'topicList',
        meta: {
          title: '题目管理',
          icon: 'guide',
          noCache: true
        }
      },
      {
        path: 'answerList',
        component: () => import('@/views/library/answerList'),
        name: 'library/answerList',
        meta: {
          title: '答案管理',
          icon: 'guide',
          noCache: true
        }
      },
      {
        path: 'commentList',
        component: () => import('@/views/library/commentList'),
        name: 'library/commentList',
        meta: {
          title: '评论管理',
          icon: 'guide',
          noCache: true
        }
      },
      {
        path: 'commentSubList',
        component: () => import('@/views/library/commentSubList'),
        name: 'library/commentSubList',
        meta: {
          title: '回复管理',
          icon: 'guide',
          noCache: true
        }
      },
      {
        path: 'questionList',
        component: () => import('@/views/library/questionList'),
        name: 'library/questionList',
        meta: {
          title: '申问题',
          icon: 'guide',
          noCache: true
        }
      },
      {
        path: 'replyList',
        component: () => import('@/views/library/replyList'),
        name: 'library/replyList',
        meta: {
          title: '申回答',
          icon: 'guide',
          noCache: true
        }
      },
      {
        path: 'roleList',
        component: () => import('@/views/library/roleList'),
        name: 'library/roleList',
        meta: {
          title: '角色管理',
          icon: 'guide',
          noCache: true
        }
      }
    ]
  },

  {
    path: '/interview',
    component: Layout,
    redirect: '/interview',
    meta: {
      title: '面试厅',
      icon: 'fullscreen'
    },
    children: [{
        path: 'interviewList',
        component: () => import('@/views/interview/interviewList'),
        name: 'interview/interviewList',
        meta: {
          title: '面试厅管理',
          icon: 'fullscreen',
          noCache: true
        }
      },
      {
        path: 'cateList',
        component: () => import('@/views/interview/cateList'),
        name: 'interview/cateList',
        meta: {
          title: '题目分类',
          icon: 'fullscreen',
          noCache: true
        }
      }, {
        path: 'topicList',
        component: () => import('@/views/interview/topicList'),
        name: 'interview/topicList',
        meta: {
          title: '题目管理',
          icon: 'fullscreen',
          noCache: true
        }
      }, {
        path: 'answerList',
        component: () => import('@/views/interview/answerList'),
        name: 'interview/answerList',
        meta: {
          title: '答案管理',
          icon: 'fullscreen',
          noCache: true
        }
      },
      {
        path: 'commentList',
        component: () => import('@/views/interview/commentList'),
        name: 'interview/commentList',
        meta: {
          title: '评论管理',
          icon: 'fullscreen',
          noCache: true
        }
      },
      {
        path: 'commentSubList',
        component: () => import('@/views/interview/commentSubList'),
        name: 'interview/commentSubList',
        meta: {
          title: '回复管理',
          icon: 'fullscreen',
          noCache: true
        }
      },
      {
        path: 'expList',
        component: () => import('@/views/interview/expList'),
        name: 'interview/expList',
        meta: {
          title: '经验谈管理',
          icon: 'fullscreen',
          noCache: true
        }
      }, {
        path: 'roleList',
        component: () => import('@/views/interview/roleList'),
        name: 'interview/roleList',
        meta: {
          title: '角色管理',
          icon: 'fullscreen',
          noCache: true
        }
      },
    ]
  },
  {
    path: '/article',
    component: Layout,
    redirect: '/article/articleCateList',
    meta: {
      title: '文章管理',
      icon: 'clipboard'
    },
    children: [{
        path: 'articleCateList',
        component: () => import('@/views/articleCate/list'),
        name: 'articleCateList',
        meta: {
          title: '分类列表',
          icon: 'clipboard',
          noCache: true
        }
      },
      {
        path: 'articleList',
        component: () => import('@/views/article/list'),
        name: 'articleList',
        meta: {
          title: '文章列表',
          icon: 'clipboard',
          noCache: true
        }
      },
      {
        path: 'addArticle',
        hidden: true,
        component: () => import('@/views/article/addArticle'),
        name: 'addArticle',
        meta: {
          title: '添加文章',
          icon: 'clipboard',
          noCache: true
        }
      },
      {
        path: 'updateArticle',
        hidden: true,
        component: () => import('@/views/article/updateArticle'),
        name: 'updateArticle',
        meta: {
          title: '编辑文章',
          icon: 'clipboard',
          noCache: true
        }
      }
    ]
  },

  {
    path: '/bannerNotice',
    component: Layout,
    redirect: '/bannerNotice/bannerList',
    meta: {
      title: '广告管理',
      icon: 'example'
    },
    children: [{
        path: 'bannerList',
        component: () => import('@/views/banner/list'),
        name: 'bannerList',
        meta: {
          title: 'banner列表',
          icon: 'example',
          noCache: true
        }
      },
      {
        path: 'noticeList',
        component: () => import('@/views/notice/list'),
        name: 'noticeList',
        meta: {
          title: '公告列表',
          icon: 'example',
          noCache: true
        }
      },
      {
        path: 'memberDocList',
        component: () => import('@/views/notice/memberDocList'),
        name: 'memberDocList',
        meta: {
          title: '协议配置',
          icon: 'example',
          noCache: true
        }
      }
    ]
  },
  /** when your routing map is too long, you can split it into small modules **/
  // componentsRouter,
  // chartsRouter,
  // nestedRouter,
  // tableRouter,
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
